package org.workdemo.back.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.workdemo.back.entity.DTO.BackPageQueryDTO;
import org.workdemo.back.entity.DzyhThb;
import org.workdemo.back.entity.result.PageResult;
import org.workdemo.back.entity.result.Result;
import org.workdemo.back.service.BackService;

import javax.annotation.Resource;

/**
 * @author xxliang
 * @Date 2025/3/29 10:44
 */
@RestController
@RequestMapping("/back")
@Api(tags = "退货申请相关接口")
@Slf4j
public class BackController {

    @Resource
    BackService backService;

    /**
     * 获取退货申请
     * @param gid
     * @return
     */
    @GetMapping("/getById")
    @ApiOperation("根据gid获取退货相关信息")
    public Result<DzyhThb> getById(String gid){
        System.out.println(gid);
        return Result.success(backService.getById(gid));
    }


    /**
     * 添加退货申请
     * @param dzyhThb
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加退货单")
    //允许进行Json格式的数据传输
    public Result addBack(@RequestBody DzyhThb dzyhThb){
        backService.addBack(dzyhThb);
        return Result.success();


    }

    /**
     * 依据GID删除退货申请
     * @param gid
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除退货申请")
    public Result deleteBack(String gid){
        backService.deleteBack(gid);
        return Result.success();
    }


    /**
     * 修改退货申请
     * @param dzyhThb
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改订单信息")
    public Result updateBack(@RequestBody  DzyhThb dzyhThb){
        backService.updateBack(dzyhThb);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("退还申请信息分页查询")
    public Result<PageResult> page(BackPageQueryDTO backPageQueryDTO){
        PageResult pageResult = backService.pageQuery(backPageQueryDTO);
        log.info(pageResult.toString());
        return Result.success(pageResult);
    }
}
